package system;

import java.util.Map;
import ehcache.EHCacheUtil;

import biz.util.YwsOLUtil;

public final class Main {
	
	public static void main(){
		getProjectLocation();					//获取项目路径
		initialProperties();					//读取配置文件
		EHCacheUtil.CreateCache();				//创建缓存
		ywsListenerLogin();						//监听者登录
		
	}
	
	//获取项目路径
	private static void getProjectLocation(){
		StaticData.PROJECT_LOCATION = Main.class.getResource("/../../").getPath().substring(1);
		System.out.println(StaticData.PROJECT_LOCATION);
	}
	

	
	/***
	 * 启动容器时初始化以下信息
	 */
	private static void initialProperties(){
		
		//new Thread(new MultThread()).start();

		Map<String, String> properties = YwsOLUtil.ReadPropertiesFromFile();
		
		StaticData.WEB_ADDRESS = properties.get("WEB_ADDRESS");
		StaticData.LOGIN_URL = properties.get("LOGIN_URL");
		StaticData.GET_YWSID_URL = properties.get("GET_YWSID_URL");
		
		StaticData.LOGIN_SUCCESS_FLAG = properties.get("LOGIN_SUCCESS_FLAG");
		StaticData.LOGIN_VALIDATE_ERROR_FLAG = properties.get("LOGIN_VALIDATE_ERROR_FLAG");
		StaticData.LOGIN_NO_OPEN_FLAG = properties.get("LOGIN_NO_OPEN_FLAG");

		StaticData.NULL_LOGINNAME_OR_PASSWORD = properties.get("NULL_LOGINNAME_OR_PASSWORD");
		StaticData.NO_MATCHINT_USERNAME_PASWORD  = properties.get("NO_MATCHINT_USERNAME_PASWORD");
		StaticData.LOGIN_SUCCESS  = properties.get("LOGIN_SUCCESS");
		StaticData.DISABLED_USER  = properties.get("DISABLED_USER");
		StaticData.LOGIN_UNKNOW_ERROR  = properties.get("LOGIN_UNKNOW_ERROR");
		
		StaticData.YWSID_AFTER = properties.get("YWSID_AFTER");
		StaticData.YWSID_BEFORE = properties.get("YWSID_BEFORE");
		
		StaticData.NICKNAME_BEFORE = properties.get("NICKNAME_BEFORE");
		StaticData.NICKNAME_AFTER = properties.get("NICKNAME_AFTER");
		
		StaticData.SESSION_USERID_NAME = properties.get("SESSION_USERID_NAME");
		StaticData.SESSION_LOGIN_IP_NAME = properties.get("SESSION_LOGIN_IP_NAME");
		StaticData.SESSION_LOGIN_FORWARDIP_NAME = properties.get("SESSION_LOGIN_FORWARDIP_NAME");
		
		
		StaticData.SYSYTEM_DENY_OUTSIDE_CONNECTION = properties.get("SYSYTEM_DENY_OUTSIDE_CONNECTION").equalsIgnoreCase("true");
		StaticData.SYSYTEM_LOGIN_LOG = properties.get("SYSYTEM_LOGIN_LOG").equalsIgnoreCase("true");
		
		StaticData.YWS_GET_PERSON_INFO_URL = properties.get("YWS_GET_PERSON_INFO_URL");
		
		StaticData.FACE_REFERER_URL = properties.get("FACE_REFERER_URL");
		
		StaticData.FACE_URL1_BEFORE = properties.get("FACE_URL1_BEFORE");
		StaticData.FACE_URL1_AFTER = properties.get("FACE_URL1_AFTER");
		StaticData.FACE_URL2_BEFORE = properties.get("FACE_URL2_BEFORE");
		StaticData.FACE_URL2_AFTER = properties.get("FACE_URL2_AFTER");
		StaticData.FACE_URL3_BEFORE = properties.get("FACE_URL3_BEFORE");
		StaticData.FACE_URL3_AFTER = properties.get("FACE_URL3_AFTER");
		
		StaticData.YWSLISTENER_USERNAME = properties.get("YWSLISTENER_USERNAME");
		StaticData.YWSLISTENER_PASSWORD = properties.get("YWSLISTENER_PASSWORD");
		StaticData.SYSTEM_THREAD_SLEEP_WAIT = Long.parseLong(properties.get("SYSTEM_THREAD_SLEEP_WAIT"));
	}
	
	//管理员登录，获取SESSIONID
	private static void ywsListenerLogin(){
		String url = StaticData.LOGIN_URL;
		url = url.replaceFirst("#username#", StaticData.YWSLISTENER_USERNAME);
		url = url.replaceFirst("#password#", StaticData.YWSLISTENER_PASSWORD);
		Map<String, String> result = YwsOLUtil.GetHTMLandSessionIDByURL(url, null);
		StaticData.YWSLISTENER_SESSIONID = result.get("sessionid");

	}
}
